import os
import cv2

cap = cv2.VideoCapture(1)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 500)  #设置宽度
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 500)  #设置长度

save = "image/"
c = 0

if not os.path.exists(save):
    os.makedirs(save)
    
while(True):
    #获取一帧图片
    ret,frame = cap.read()
    
    #播放每一帧图片
    if c%5==0:
        cv2.imshow('frame',frame)
        cv2.imwrite(os.path.join(save,"%d.jpg"%(c)),frame)
    c+=1
    
    if cv2.waitKey(1) &0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
    